// view/my/xgdp/xgdp.js
let app = getApp()
let yuming = app.globalData.yuming
var shuzong = []
var shu = []
const util = require('../../pages/components/util');
var chaninese = app.globalData.chaninese
const request = require('../../config/request');
Page({
  ...request,
  /**
   * 页面的初始数据
   */
  data: {
    buttonClicked: false,
    heights: '',
    title: "经营资质",
    hanglist: [], //行业类别
    ytList: [],
    otherhyList: [],
    hangindex: 0, //行业index
    ytindex: 0, //业态分类index
    otherhyindex: 0,
    jielist: [], //所属街道
    jieindex: 0, //所属街道index
    zzxx: '', //店铺营业执照
    photo: [], //其他证照
    dtz: [], //店头照
    shengguo: '请选择省',
    shiguo: '请选择市',
    quguo: '请选择区',
    shenglist: [],
    shilist: [],
    qulist: [],
    shengindex: 0,
    shiindex: 0,
    quindex: 0,
    pid: '', //省id
    cid: '', //市id
    quid: '', //区id
    hangyeguo: '请选择行业类别', //行业类别
    yetaiguo: '请选择业态分类', //业态分类
    otherhyguo: '请选择其他行业分类',
    dianname: '', //店铺名称
    fapename: '', //法人负责人
    shxydm: '', //社会信用代码
    hangyeid: '', //行业类别id
    yetaiid: '', //业态分类id
    otherhyid: '', //其他行业id
    xiangadress: '', //详细地址
    ssjgs: '', //所属监管所
    jieguo: '请选择所属市场', //所属市场
    myjgyguo: '请选择我的监管员', //我的监管员
    myjgylist: [], //我的监管员
    yyzz: '', //营业执照
    // sfz: '', //身份证
    diantz: '', //店头照
    miangz: '', //免冠照
    dianplogo: '', //店铺logo
    wudianplogo: '', //不带域名的logo
    wudiantz: '', //不带域名店头照
    wuyyzz: '', //不带域名营业执照
    // wusfz: '', //不带域名身份证
    wumiangz: '', //不带域名免冠照
    jgsid: '', //所属监管所id
    scjdid: '', //所属市场id
    myjfid: '', //我的监管员id
    ischong: false,
    huan: [],
    currtab: 0,
    zhis: [], //知识产权列表
    qiyebian: 0, //0显示 1编辑
    page: 1,
    yuming: yuming,
    xukebian: 0, //0点击编辑 1点击确定
    shopName: '', //许可证企业名称
    shopPerson: '', //许可证法人
    shopCode: '', //许可证社会信用代码
    licenceCode: '', //许可证编号
    issuingAuthority: '', //许可证发证机关
    // subjectName: '', //主体业态名称 店铺名
    magmentFanwei: '', //经营范围

    xkzlist: [
      //   {
      //   id: 1,
      //   name: '餐饮服务许可证',
      //   jylb: '食品',
      //   image: yuming + 'upload/images/2022-06-08/62a04ea57cbbc.png',
      //   fzdate: '2019-10-28',
      //   qzdate: '2023-10-29',
      //   isBian: false
      // }
    ],
    xkzName: '', //许可证名称
    jylbindex: 0,
    jylbid: 0,
    jylbList: [], //经营类别数组
    magmentClass: '请选择经营类别', //经营类别
    xukezhao: '', //许可证照片
    wuxukezhao: '', //无域名许可证照片
    starTime: '请选择发证日期', //发证日期
    endTime: '请选择有效期', //有效期至
  },
  bindinput(e) {
    let val = e.detail.value
    if (this.data.currtab == 0) {
      this.setData({
        dianname: val
      })
    } else {
      this.setData({
        xkzName: val
      })
    }
  },
  // 发证日期
  bindfazheng: function (e) {
    this.setData({
      starTime: e.detail.value
    })
  },
  bindyouxiao(e) {
    if (new Date(e.detail.value).getTime() < Date.parse(new Date())) {
      wx.showToast({
        title: '有效期不可小于当前时间',
        icon: 'none'
      })
      this.setData({
        endTime: '请选择有效期'
      })
    } else {
      this.setData({
        endTime: e.detail.value
      })
    }
  },
  // 删除
  shanchu(e) {
    console.log(e)
    var id = e.currentTarget.dataset.id
    console.log(id)
    var that = this
    let title = ''
    if (that.data.currtab == 1) {
      title = '请谨慎删除许可证！'
    } else {
      title = '您确定要删除吗？'
    }
    wx.showModal({
      title,
      cancelText: '取消',
      confirmText: '确定',
      success: function (res) {
        if (res.confirm) {
          if (that.data.currtab == 2) {
            console.log("确定,知识产权删除")
            that.dele(id)
          } else {
            console.log("确定,许可证删除")
            that.xu_shan_chu(id)
          }
        } else {
          console.log("取消")
        }
      }
    })
  },
  dele(id) {
    let that = this
    this.myRequest(yuming + 'shop/ShopDelProperty', {
      id: id,
      shopId: wx.getStorageSync('shopId')
    }, "POST").then(res => {
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      if (res.data.code == 200) {
        that.zscqxx()
      }
    })
  },
  // 生成二维码
  sheng() {
    wx.navigateTo({
      url: '/my_other/xinxilr/xinxilr',
    })
  },
  //营业执照一键识别
  yjsbyyz(imgurl) {
    wx.showLoading({
      title: '识别营业执照中',
      icon: 'none'
    })
    let that = this
    this.myRequest(yuming + 'Besall/ai_business_license_v1', {
      imgUrl: imgurl
    }, "POST").then(res => {
      if (res.data.code == 200) {
        wx.showToast({
          title: '识别成功',
          icon: 'none'
        })
        wx.hideLoading();
        let data = res.data.data.营业执照识别实体信息
        that.setData({
          dianname: data.企业名称,
          fapename: data.企业法人,
          shxydm: data.企业统一社会信用编码,
          shengguo: data.企业所在省份,
          shiguo: data.企业所在城市,
          quguo: data.企业所在区域,
          xiangadress: data.企业注册地址,
        })
        let pid = that.data.shenglist.filter(item => item.areaName == that.data.shengguo)[0].areaId;
        that.setData({
          pid: pid
        })
        that.doCity(pid);
      }
    })
  },
  async doCity(pid) {
    await this.getCity0(pid);
    console.log(this.data.shilist);
    let cid = this.data.shilist.filter(item => item.areaName == this.data.shiguo)[0].areaId;
    this.setData({
      cid: cid
    })
    this.doArea(cid);
  },
  async doArea(cid) {
    await this.getArea0(cid);
    console.log(this.data.qulist);
    let quid = this.data.qulist.filter(item => item.areaName == this.data.quguo)[0].areaId;
    this.setData({
      quid: quid
    })
  },
  // 切换
  qies(e) {
    var index = e.currentTarget.dataset.currtab
    this.setData({
      currtab: index,
      qiyebian: 0,
      xukebian: 0,
      xukezhao: '',
      shopName: '',
      shopPerson: '',
      shopCode: '',
      licenceCode: '',
      issuingAuthority: '',
      starTime: '请选择发证日期',
      endTime: '请选择有效期',
      // subjectName: '',
      magmentClass: '请选择经营类别',
      magmentFanwei: ''
    })
    console.log(index)
    if (index == 0) {
      this.shxx() //商户信息
    } else if (index == 1) {
      this.xkzxx() //许可证
    } else {
      this.zscqxx() //知识产权
    }
  },
  // 点击编辑
  bianji() {
    var that = this
    setTimeout(function () {
      that.setData({
        qiyebian: 1,
        buttonClicked: false
      })
    }, 500)
  },
  // 保存验证
  baocun() {
    if (this.data.dianname == '') {
      wx.showToast({
        title: '店铺/企业名称不能为空',
        icon: 'none'
      })
    } else if (this.data.fapename == '') {
      wx.showToast({
        title: '法人/负责人不能为空',
        icon: 'none'
      })
    } else if (this.data.shxydm == '') {
      wx.showToast({
        title: '社会信用代码不能为空',
        icon: 'none'
      })
    } else if (this.data.hangyeid == '') {
      wx.showToast({
        title: '请选择行业类别',
        icon: 'none'
      })
    } else if (this.data.hangyeid == 13 && this.data.yetaiid == '') {
      wx.showToast({
        title: '请选择业态分类',
        icon: 'none'
      })
    } else if (this.data.otherhyid == '') {
      wx.showToast({
        title: '请选择其他行业',
        icon: 'none'
      })
    } else if (this.data.shengguo == '请选择省') {
      wx.showToast({
        title: '请选择省',
        icon: 'none'
      })
    } else if (this.data.shiguo == '请选择市') {
      wx.showToast({
        title: '请选择市',
        icon: 'none'
      })
    } else if (this.data.quguo == '请选择区') {
      wx.showToast({
        title: '请选择区',
        icon: 'none'
      })
    } else if (this.data.xiangadress == '') {
      wx.showToast({
        title: '详细地址不能为空',
        icon: 'none'
      })
    } else if (this.data.jieguo == '请选择所属市场') {
      wx.showToast({
        title: '请选择所属市场',
        icon: 'none'
      })
    } else if (this.data.myjgyguo == '请选择我的监管员') {
      wx.showToast({
        title: '请选择我的监管员',
        icon: 'none'
      })
    } else if (this.data.wuyyzz == '') {
      wx.showToast({
        title: '请上传营业执照',
        icon: 'none'
      })
    }
    // else if (this.data.wusfz == '') {
    //   wx.showToast({
    //     title: '请上传身份证',
    //     icon: 'none'
    //   })
    // }
    else if (this.data.wudiantz == '') {
      wx.showToast({
        title: '请上传店头照',
        icon: 'none'
      })
    } else if (this.data.wumiangz == '') {
      wx.showToast({
        title: '请上传免冠照',
        icon: 'none'
      })
    } else {
      this.que()
    }
  },
  // 点击确定接口
  que() {
    let that = this
    that.setData({
      buttonClicked: true
    })
    let hyid = 0;
    if (that.data.hangyeid == 13) {
      hyid = that.data.yetaiid
    } else {
      hyid = that.data.hangyeid
    }
    this.myRequest(yuming + 'shop/shopSaveInfo', {
      shopId: wx.getStorageSync('shopId'),
      shopType: that.data.shopType,
      mobile: that.data.mobile,
      shopName: that.data.dianname,
      legalPerson: that.data.fapename,
      socialCode: that.data.shxydm,
      stryId: hyid,
      pid: that.data.pid,
      cid: that.data.cid,
      did: that.data.quid,
      shopAddress: that.data.xiangadress,
      regulatorOffice: that.data.jgsid,
      regulatorStreet: that.data.scjdid,
      shopSupervisor: that.data.myjfid,
      businessLicense: that.data.wuyyzz,
      // idcartLicenses: that.data.wusfz,
      shopHeadPhoto: that.data.wudiantz,
      bareheadedPhoto: that.data.wumiangz,
      hangye_label: that.data.otherhyid,
      shopLogo: that.data.wudiantz
    }, "POST").then(res => {
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      if (res.data.code == 200) {
        setTimeout(function () {
          that.setData({
            qiyebian: 0
          })
          that.shxx()
        }, 1500)
      }
    })
  },
  // 商户信息
  shxx() {
    var that = this
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    this.myRequest(yuming + 'Besall/findShopInfos', {
      shopId: wx.getStorageSync('shopId'),
    }, "POST").then(res => {
      wx.hideLoading()
      var data = res.data.data
      var b = that.data.hanglist
      let otherhyList = that.data.otherhyList
      let otherhyguo = '';
      otherhyList.forEach(item => {
        if (data.hangye_label == item.id) {
          otherhyguo = item.name
          that.setData({
            otherhyguo
          })
        }
      })
      let hangyeguo = '';
      let yetaiguo = '';
      let hangyeid = '';
      let yetaiid = '';
      if (!data.stryId_fid) {
        hangyeguo = data.cartTitle;
        hangyeid = data.stryId;
        yetaiguo = '请选择业态分类'
      } else {
        hangyeguo = data.cartprol__cartTitle;
        yetaiguo = data.cartTitle;
        hangyeid = data.stryId_fid;
        yetaiid = data.stryId;
      }
      var resa
      that.setData({
        mobile: data.mobile,
        shopType: data.shopType,
        dianname: data.shopName,
        fapename: data.legalPerson,
        shxydm: data.socialCode,
        xiangadress: data.shopAddress,
        shengguo: data.pname,
        shiguo: data.cname,
        quguo: data.dname,
        jianguansuo: data.Office,
        quid: data.did,
        pid: data.pid,
        cid: data.cid,
        jieguo: data.Street,
        myjgyguo: data.visor,
        hangyeguo,
        yetaiguo,
        hangyeid,
        yetaiid,
        otherhyid: data.hangye_label,
        scjdid: data.regulatorStreet,
        jgsid: data.regulatorOffice,
        myjfid: data.shopSupervisor,
      })
      that.getCity(data.pid)
      console.log(data.cid)
      that.getArea(data.cid)

      that.jgs(0)
      if (data.businessLicense == '') { //营业执照
        that.setData({
          yyzz: '',
          wuyyzz: ''
        })
      } else {
        that.setData({
          yyzz: yuming + data.businessLicense,
          wuyyzz: data.businessLicense,
        })
      }
      // if (data.idcartLicenses == '') { //身份证
      //   that.setData({
      //     sfz: '',
      //     wusfz: ''
      //   })
      // } else {
      //   that.setData({
      //     sfz: yuming + data.idcartLicenses,
      //     wusfz: data.idcartLicenses,
      //   })
      // }
      if (data.shopHeadPhoto == '') { //店头照
        that.setData({
          diantz: '',
          wudiantz: ''
        })
      } else {
        that.setData({
          diantz: yuming + data.shopHeadPhoto,
          wudiantz: data.shopHeadPhoto,
        })
      }
      if (data.bareheadedPhoto == '') { //免冠照
        that.setData({
          miangz: '',
          wumiangz: ''
        })
      } else {
        that.setData({
          miangz: yuming + data.bareheadedPhoto,
          wumiangz: data.bareheadedPhoto,
        })
      }
      if (data.shopLogo == '') { //店铺logo
        that.setData({
          dianplogo: '',
          wudianplogo: ''
        })
      } else {
        that.setData({
          dianplogo: yuming + data.shopLogo,
          wudianplogo: data.shopLogo,
        })
      }
      let stryId = '';
      if (!data.stryId_fid) {
        stryId = data.stryId
      } else {
        stryId = data.stryId_fid
      }
      let jieguo = b.find(item => {
        return stryId == item.id;
        // return 99999 == item.id;
      })
      if (jieguo != undefined) {
        resa = jieguo.cartTitle
        console.log("找到了" + resa)
        that.setData({
          hangyeguo: resa
        })
      } else {
        console.log(b)
        console.log(stryId)
        console.log(jieguo)
        console.log("没找到")
        resa = b[0].cartTitle
        wx.showToast({
          title: '类别已更改，请重新选择，点击编辑',
          icon: 'none'
        })
      }
      this.getytList()
    })
  },
  // 查看更多
  lookmore() {
    shuzong = this.data.zhis
    this.setData({
      page: (this.data.page) + 1
    })
    this.zscqxx()
  },
  // 知识产权信息
  zscqxx() {
    let that = this
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    this.myRequest(yuming + 'shop/ShopSelectProperty', {
      shopId: wx.getStorageSync('shopId'),
      page: that.data.page
    }, "POST").then(res => {
      wx.hideLoading();
      shu = res.data.data
      if (that.data.page != 1) {
        if (shu.length == 0) {
          wx.showToast({
            title: '没有更多数据了~',
            icon: "none"
          })
          that.setData({
            zhis: []
          })
        }
      }
      that.setData({
        zhis: shuzong.concat(shu)
      })
    })
  },
  showModal(e) {
    var aaa = e.currentTarget.dataset.aaa
    var img = e.currentTarget.dataset.img
    this.setData({
      fdaaa: aaa,
      fdimg: img,
      cxscindex: e.currentTarget.dataset.index
    })
    let {
      type
    } = e.currentTarget.dataset, va = '';
    if (type == 's2') {
      va = "s2";
    }
    this.setData({
      [va]: true
    })
  },
  confirmbtn(e) {
    console.log(e)
    console.log('点击了从新上传！')
    var aaa = this.data.fdaaa
    var that = this;
    this.myChooseImage(1).then(res => {
      const tempFilePaths = res.tempFilePaths
      this.myUploadImg(tempFilePaths[0], 'file').then(res => {
        var data = JSON.parse(res.data)
        wx.showToast({
          title: data.msg,
          icon: 'none'
        })
        var urls = data.httpUrl + data.imgUrl
        //营业执照
        if (aaa == 5) {
          that.yjsbyyz(data.imgUrl);
          that.setData({
            yyzz: urls,
            wuyyzz: data.imgUrl
          })
        }
        // 身份证
        // if (aaa == 6) {
        //   that.setData({
        //     sfz: urls,
        //     wusfz: data.imgUrl
        //   })
        // }
        // 店头照
        if (aaa == 7) {
          that.setData({
            diantz: urls,
            wudiantz: data.imgUrl
          })
        }
        // 免冠照
        if (aaa == 8) {
          that.setData({
            miangz: urls,
            wumiangz: data.imgUrl
          })
        }
        // 店铺logo
        if (aaa == 9) {
          that.setData({
            dianplogo: urls,
            wudianplogo: data.imgUrl
          })
        }
        // 许可证证件照
        if (aaa == 10) {
          that.data.xkzlist[that.data.cxscindex].licenceImg = [urls];
          that.setData({
            xukezhao: urls,
            wuxukezhao: data.imgUrl,
            xkzlist: that.data.xkzlist
          })
        }
      })
    })

  },
  cancelBtn() {
    console.log('点击了放大！')
    wx.previewImage({
      urls: [this.data.fdimg]
    })
  },
  getIptValue(e) {
    console.log(e.detail)
  },
  // 点击放大
  fangdas(e) {
    var img = e.currentTarget.dataset.img
    wx.previewImage({
      urls: [img]
    })
  },
  fd(e) {
    var img = e.currentTarget.dataset.img
    var list = e.currentTarget.dataset.list
    var arr = []
    for (let i in list) {
      arr.push(list[i]); //属性
    }
    wx.previewImage({
      current: img,
      urls: arr
    })
  },
  // 省
  bindsheng(e) {
    var id = this.data.shenglist[e.detail.value].areaId
    this.setData({
      shengguo: this.data.shenglist[e.detail.value].areaName,
      pid: id,
      shiguo: '请选择市',
      cid: '',
      quguo: '请选择区',
      quid: ''
    })
    this.getCity(id)
  },
  // 市
  bindshi(e) {
    var id = this.data.shilist[e.detail.value].areaId
    if (this.data.shengguo == '请选择省') {
      wx.showToast({
        title: '请选择省',
        icon: 'none'
      })
    } else {
      this.setData({
        shiguo: this.data.shilist[e.detail.value].areaName,
        cid: id,
        quguo: '请选择区',
        quid: ''
      })
      this.getArea(id)
    }
  },
  // 区
  bindqu(e) {
    this.setData({
      quguo: this.data.qulist[e.detail.value].areaName,
      quid: this.data.qulist[e.detail.value].areaId,
    })
    this.jgs(0)
  },
  // 获取省列表
  getProvince: function () {
    let that = this
    this.myRequest(yuming + 'Besall/areaList', {
      parentId: 0,
      areaType: 0,
    }, "POST").then(res => {
      that.setData({
        shenglist: res.data.data, //省级原始数据
      })
      // let defaultCode = that.data.shenglist[0].areaId //使用第一项当作参数获取市级数据
      // if (defaultCode) {
      //   that.getCity(defaultCode) //获取市区数据
      // }
    })
  },
  //获取市列表
  getCity: function (id) {
    let that = this
    this.myRequest(yuming + 'Besall/areaList', {
      parentId: id,
      areaType: 1,
    }, "POST").then(res => {
      that.setData({
        shilist: res.data.data, //保持市级数据
      })
      let defaultCode = that.data.shilist[0].areaId //获取第一个市的区级数据
      if (defaultCode) {
        // that.getArea(defaultCode) //获取区域数据
      }
    })
  },
  //获取区列表
  getArea: function (id) {
    var that = this
    this.myRequest(yuming + 'Besall/areaList', {
      parentId: id,
      areaType: 2,
    }, "POST").then(res => {
      console.log(res)
      that.setData({
        qulist: res.data.data,
      })
    })
  },
  //获取市列表
  getCity0: function (id) {
    return new Promise((resolve, reject) => {
      let that = this
      this.myRequest(yuming + 'Besall/areaList', {
        parentId: id,
        areaType: 1,
      }, 'POST').then(res => {
        that.setData({
          shilist: res.data.data, //保持市级数据
        })
        let defaultCode = that.data.shilist[0].areaId //获取第一个市的区级数据
        if (defaultCode) {
          that.getArea(defaultCode) //获取区域数据
        }
        resolve(res);
      }).catch(err => {
        reject(err);
      })
    })
  },
  //获取区列表
  getArea0: function (id) {
    return new Promise((resolve, reject) => {
      let that = this
      this.myRequest(yuming + 'Besall/areaList', {
        parentId: id,
        areaType: 2,
      }, 'POST').then(res => {
        that.setData({
          qulist: res.data.data, //区列表
          quid: res.data.data[0].areaId
        })
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  // 获取经营类别
  getjylb() {
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    this.myRequest(yuming + 'Besall/public_class_options', {
      type_mold: 2,
      pid: 0
    }, 'POST').then(res => {
      wx.hideLoading();
      if (res.data.code == 200) {
        let arr = res.data.data;
        let jylbList = [];
        arr.forEach(item => {
          jylbList.push({
            id: item.id,
            name: item.name
          })
        })
        this.setData({
          jylbList
        })
      }
    })
  },
  // 经营类别选择
  jylb(e) {
    let index = e.detail.value;
    this.setData({
      magmentClass: this.data.jylbList[index].name,
      jylbid: this.data.jylbList[index].id
    });
  },
  // 点击区获取所属监管所
  jgs(id) {
    var that = this
    this.myRequest(yuming + 'shop/shopAreaMarketerList', {
      cityId: that.data.quid,
      fid: id
    }, "POST").then(res => {
      that.setData({
        jiangslist: res.data.data
      })
      if (that.data.jiangslist.length != 0) {
        // var id = res.data.data[0].id
        var id = that.data.jgsid
        that.shsc(id)
        that.setData({
          ssjgs: res.data.data[0].mation,
          // jieguo: '请选择所属市场',
          jielist: [],
          // myjgyguo: '请选择我的监管员',
          myjgylist: []
        })
      } else {
        that.setData({
          ssjgs: '暂无',
          jieguo: '请选择所属市场',
          jielist: [],
          myjgyguo: '请选择我的监管员',
          myjgylist: []
        })
      }
    })
  },
  // 所属市场
  shsc(id) {
    var that = this
    this.myRequest(yuming + 'shop/shopAreaMarketerList', {
      cityId: that.data.quid,
      fid: id
    }, "POST").then(res => {
      that.setData({
        jielist: res.data.data
      })
      if (that.data.jielist.length != 0) {
        var id = res.data.data[0].id
        that.jgy(id)
      } else {
        that.setData({
          // myjgyguo: '请选择我的监管员',
          myjgylist: []
        })
      }
    })
  },
  // 监管员
  jgy(id) {
    var that = this
    this.myRequest(yuming + 'shop/shopAreaMarketerList', {
      cityId: that.data.quid,
      fid: id
    }, "POST").then(res => {
      that.setData({
        myjgylist: res.data.data
      })
    })
  },
  // 上传
  chuan(e) {
    var aaa = e.currentTarget.dataset.aaa
    let index = e.currentTarget.dataset.index
    var that = this;
    //选取图片
    this.myChooseImage(1).then(res => {
      const tempFilePaths = res.tempFilePaths
      this.myUploadImg(tempFilePaths[0], 'file').then(res => {
        var data = JSON.parse(res.data)
        wx.showToast({
          title: data.msg,
          icon: 'none'
        })
        var urls = data.httpUrl + data.imgUrl
        //营业执照
        if (aaa == 5) {
          that.setData({
            yyzz: urls,
            wuyyzz: data.imgUrl
          })

        }
        // 身份证
        // if (aaa == 6) {
        //   that.setData({
        //     sfz: urls,
        //     wusfz: data.imgUrl
        //   })
        // }
        // 店头照
        if (aaa == 7) {
          that.setData({
            diantz: urls,
            wudiantz: data.imgUrl
          })
        }
        // 免冠照
        if (aaa == 8) {
          that.setData({
            miangz: urls,
            wumiangz: data.imgUrl
          })
        }
        // 店铺logo
        if (aaa == 9) {
          that.setData({
            dianplogo: urls,
            wudianplogo: data.imgUrl
          })
        }
        // 许可证证件照
        if (aaa == 10) {
          that.data.xkzlist[index].licenceImg = [urls];
          that.setData({
            xukezhao: urls,
            wuxukezhao: data.imgUrl,
            xkzlist: that.data.xkzlist
          })
        }
      })
    })
    // wx.chooseImage({
    //   success(res) {
    //     const tempFilePaths = res.tempFilePaths
    //     wx.uploadFile({
    //       url: yuming + 'Besall/Upload',
    //       filePath: tempFilePaths[0],
    //       name: 'file',
    //       formData: {

    //       },
    //       success(res) {
    //         var data = JSON.parse(res.data)
    //         wx.showToast({
    //           title: data.msg,
    //           icon: 'none'
    //         })
    //         var urls = data.httpUrl + data.imgUrl
    //         //营业执照
    //         if (aaa == 5) {
    //           that.setData({
    //             yyzz: urls,
    //             wuyyzz: data.imgUrl
    //           })
    //         }
    //         // 身份证
    //         if (aaa == 6) {
    //           that.setData({
    //             sfz: urls,
    //             wusfz: data.imgUrl
    //           })
    //         }
    //         // 店头照
    //         if (aaa == 7) {
    //           that.setData({
    //             diantz: urls,
    //             wudiantz: data.imgUrl
    //           })
    //         }
    //         // 免冠照
    //         if (aaa == 8) {
    //           that.setData({
    //             miangz: urls,
    //             wumiangz: data.imgUrl
    //           })
    //         }
    //         // 店铺logo
    //         if (aaa == 9) {
    //           that.setData({
    //             dianplogo: urls,
    //             wudianplogo: data.imgUrl
    //           })
    //         }
    //         // 许可证证件照
    //         if (aaa == 10) {
    //           that.setData({
    //             xukezhao: urls,
    //             wuxukezhao: data.imgUrl
    //           })
    //         }
    //       }
    //     })
    //   }
    // })
  },
  // 行业类别
  hangs(e) {
    let index = e.detail.value
    console.log(this.data.hanglist[index].cartTitle);
    console.log(this.data.hanglist[index].id);
    this.setData({
      hangyeguo: this.data.hanglist[index].cartTitle,
      hangyeid: this.data.hanglist[index].id,
    });
    this.getytList();
  },
  yetais(e) {
    this.setData({
      yetaiguo: this.data.ytList[e.detail.value].cartTitle,
      yetaiid: this.data.ytList[e.detail.value].id,
    });
    console.log(this.data.yetaiguo)
    console.log(this.data.yetaiid)
    wx.setStorageSync('ytName', this.data.yetaiguo)
    this.getytList();
  },
  // 其他行业类别
  otherhy(e) {
    this.setData({
      otherhyguo: this.data.otherhyList[e.detail.value].name,
      otherhyid: this.data.otherhyList[e.detail.value].id,
    });
  },
  getytList() {
    let that = this
    this.myRequest(yuming + 'Besall/cartrelationList', {
      typeMold: 2,
      fid: that.data.hangyeid
    }, 'POST').then(res => {
      that.setData({
        ytList: res.data.data
      })
    })
  },
  // 所属市场
  jies(e) {
    var id = this.data.jielist[e.detail.value].id
    this.setData({
      jieguo: this.data.jielist[e.detail.value].mation,
      scjdid: id
    });
    this.jgy(id)
  },
  // 我的监管员
  bindmyjgy(e) {
    this.setData({
      myjgyguo: this.data.myjgylist[e.detail.value].mation,
      myjfid: this.data.myjgylist[e.detail.value].id
    })
  },
  backs() {
    wx.navigateBack({
      delta: 1
    })
  },
  // 行业类别查询
  hylb() {
    var that = this
    var typeMold = ''
    var shopType = wx.getStorageSync('shopType')
    if (shopType == 0) { //0个体 1企业
      typeMold = 2 //1企业 2个体户

    }
    if (shopType == 1) {
      typeMold = 1
    }
    this.myRequest(yuming + 'Besall/cartrelationList', {
      shopId: wx.getStorageSync('shopId'),
      typeMold: typeMold
    }, "POST").then(res => {
      this.setData({
        hanglist: res.data.data,
        otherhyList: res.data.hangyeLabel
      })
    })
  },
  // 许可证信息
  xkzxx() {
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    this.myRequest(yuming + 'Besall/shop_licence_list', {
      shopId: wx.getStorageSync('shopId')
    }, "POST").then(res => {
      wx.hideLoading()
      if (res.data.code == 200) {
        let xkzlist = res.data.data
        xkzlist.forEach(item => {
          item.isBian = false
        })
        this.setData({
          xkzlist,
        })
      }
    })
  },
  // 知识产权添加
  jias() {
    wx.navigateTo({
      url: '/page_one/zsadd/zsadd',
    })
  },

  // 许可证删除
  xu_shan_chu(id) {
    this.myRequest(yuming + 'Besall/delectShopLicence', {
      id
    }, 'POST').then(res => {
      if (res.data.code == 200) {
        this.xkzxx();
      }
    })
  },
  // 许可证验证
  xu_yan(e) {
    let id = e.currentTarget.dataset.id
    let index = e.currentTarget.dataset.index
    if (this.data.xkzName == '') {
      wx.showToast({
        title: '请输入证件名称',
        icon: 'none'
      })
    } else if (this.data.magmentClass == '请选择经营类别') {
      wx.showToast({
        title: '请选择经营类别',
        icon: 'none'
      })
    } else if (this.data.xukezhao == '') {
      wx.showToast({
        title: '请上传许可证照片',
        icon: 'none'
      })
    } else if (this.data.starTime == '请选择发证日期') {
      wx.showToast({
        title: '请选择发证日期',
        icon: 'none'
      })
    } else if (this.data.endTime == '请选择有效期') {
      wx.showToast({
        title: '请选择有效期',
        icon: 'none'
      })
    } else {
      this.xu_bao(id, index)
    }
  },
  // 许可证保存
  xu_bao(id, index) {
    let that = this;
    that.setData({
      buttonClicked: true
    })
    console.log(id);
    let data = {}
    if (id != undefined) {
      data = {
        id,
        shopId: wx.getStorageSync('shopId'),
        shopName: that.data.xkzName,
        magmentClass: that.data.jylbid,
        licenceImg: that.data.wuxukezhao,
        starTime: that.data.starTime,
        endTime: that.data.endTime,
      }
    } else {
      data = {
        shopId: wx.getStorageSync('shopId'),
        shopName: that.data.xkzName,
        magmentClass: that.data.jylbid,
        licenceImg: that.data.wuxukezhao,
        starTime: that.data.starTime,
        endTime: that.data.endTime,
      }
    }
    this.myRequest(yuming + 'shop/shopSaveLicence', data, "POST").then(res => {
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      if (res.data.code == 200) {
        this.data.xkzlist[index].isBian = false
        that.setData({
          xukebian: 0,
          xkzlist: this.data.xkzlist
        })
        that.xkzxx()
        setTimeout(() => {
          that.setData({
            buttonClicked: false
          })
        }, 1000)
      }
    })
  },
  quedingadd() {
    let that = this
    wx.showModal({
      title: '确定要添加许可证吗？',
      cancelText: '取消',
      confirmText: '确定',
      success: function (res) {
        if (res.confirm) {
          that.addxkz();
        } else {
          console.log("取消")
        }
      }
    })
  },
  // 添加其他许可证
  addxkz() {
    setTimeout(() => {
      wx.pageScrollTo({
        scrollTop: 99999,
        duration: 100
      });
    }, 100)
    this.data.xkzlist.forEach(item => {
      if (item.name == '') {
        this.setData({
          isTian: 1
        })
      } else {
        this.setData({
          isTian: 0
        })
      }
    })
    if (this.data.xukebian == 1) {
      wx.showToast({
        title: '请先保存当前许可证',
        icon: 'none'
      })
    } else if (this.data.isTian == 1) {
      wx.showToast({
        title: '请先填写许可证',
        icon: 'none'
      })
    } else {
      let xkzlist = this.data.xkzlist;
      xkzlist.push({
        shopName: '',
        magmentClass: '请选择经营类别',
        licenceImg: '',
        starTime: '',
        endTime: '',
        isBian: true
      })
      this.setData({
        xkzlist,
        xkzName: '',
        magmentClass: '请选择经营类别',
        starTime: '请选择发证日期', //发证日期
        endTime: '请选择有效期', //有效期至
        xukebian: 1
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.currtab);
    let currtab = ''
    if (options.currtab) {
      currtab = options.currtab
    } else {
      currtab = 0
    }
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      title: options.title,
      currtab
    })
    this.getProvince() //获取省
    this.hylb() // 行业类别
    var that = this
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    setTimeout(function () {
      that.shxx() //商户信息
    }, 1000)
    let huan = [];
    if (wx.getStorageSync('stryId') == 6) {
      huan = ['经营资质', '许可证'];
    } else {
      huan = ['经营资质', '许可证', '知识产权'];
    }
    this.setData({
      huan,
      hyid: wx.getStorageSync('stryId')
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getjylb();
    this.zscqxx() //知识产权
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})